<?php

/**
 *  @author  Lynn Cho <lynncho@live.com>
 *  @createTime  2016-9-1 14:51:58
 *  @copyright  shewen technology
 *  @descrition  
 */
class Permission {

    /**
     * custom md5 for password
     * @param str $password
     * @return str|boolean
     */
    public function customMD5($password) {
        if (!empty($password)) {
            $password = str_split($password);
            $password = implode('A', $password);
            $password = md5($password);
            return $password;
        } else {
            return false;
        }
    }

    /**
     * translate type code to words
     * @param array $arr_num
     * @return array
     */
    public function powerWords($arr_num) {
        if (is_array($arr_num)) {
            foreach ($arr_num as $key => $val) {
                switch ($val['power']) {
                    case 4:
                        $arr_num[$key]['power'] = '综合管理员';
                        break;
                    case 3:
                        $arr_num[$key]['power'] = '客服管理员';
                        break;
                    case 2:
                        $arr_num[$key]['power'] = '站点管理员';
                        break;
                    case 1:
                        $arr_num[$key]['power'] = '未授权';
                        break;
                    case 0:
                        $arr_num[$key]['power'] = '超级管理员';
                        break;
                    default :
                        $arr_num[$key]['power'] = '未知类型';
                }
            }
            return $arr_num;
        }
    }

    /**
     * marking power level according to detail permission
     * @param array $powerlist
     * @return int
     */
    public function markingPower($powerlist) {
        $power = 1;
        if (!empty($powerlist) && is_array($powerlist)) {
            foreach ($powerlist as $val) {
                if ((int) $val === 1)
                    $power = 2;
                if ((int) $val === 8 || (int) $val === 9) {
                    if ($power === 2) {
                        $power = 4;
                    } else {
                        $power = 3;
                    }
                }
            }
        }
        return $power;
    }

    /**
     * for easyui select
     * @return array
     */
    public function getGeneralPermissionList() {
        return array(
            0 => array('id' => 999, 'text' => '--', 'selected' => true),
            1 => array('id' => 0, 'text' => '超级管理员'),
            2 => array('id' => 1, 'text' => '未授权'),
            3 => array('id' => 2, 'text' => '站点管理员'),
            4 => array('id' => 3, 'text' => '客服管理员'),
            5 => array('id' => 4, 'text' => '综合管理员')
        );
    }

}
